package com.jnshu.controller;

import com.jnshu.pojo.Course;
import com.jnshu.service.BackCourseService;
import com.jnshu.tools.resultUtils.ResultBean;
import lombok.extern.java.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName BackCourseService
 * @Descrintion
 * @Author bd
 * @Date 2019/8/3 22:19
 * @Version 1.0
 **/
@RestController
@Log
public class    BackCourseController {

    @Autowired
    BackCourseService backCourseService;

    //    资料列表
    @GetMapping(value = "/course/list")
    public ResultBean aSelectList(Course course, @RequestParam(defaultValue = "10") int pageSize,
                                  @RequestParam(defaultValue = "1") int pageNum) {
        log.info("传入的每页数量为" + pageSize + ",页码为" + pageNum);
        return backCourseService.aSelectList(course, pageSize, pageNum);
    }



    //上下架
    @PutMapping(value = "/course/status")
    public ResultBean aStatus(@RequestParam(value = "id") long id,
                              @RequestParam(value = "status") int status) {
        log.info("上下架传入的参数id为" + id + ",status为" + status);
        return backCourseService.aStatus(id, status);

    }

    //删除课程
    @DeleteMapping(value = "/course")
    public ResultBean deleteByPrimaryKey(@RequestParam long id) {
        log.info("删除课程的id为" + id);
        return backCourseService.deleteByPrimaryKey(id);
    }

    //视频详情
    @GetMapping(value = "/video")
    public ResultBean aSelectVideo(Long id) {
        log.info("查询的视频id为" + id);
        return backCourseService.aSelectVideo(id);
    }

    //新增视频
    @PostMapping(value = "/video")
    public ResultBean aInsertVideo(Course course) {
        log.info("新增视频对象为" + course);
        return backCourseService.aInsertVideo(course);

    }

    //更新视频
    @PutMapping(value = "/video")
    public ResultBean aUpdateVideo(Course course) {
        log.info("更新视频对象为" + course);
        return backCourseService.aUpdateVideo(course);
    }

    //文章详情
    @GetMapping(value = "/content")

    public ResultBean aSelectContent(Long id) {
        log.info("查询的文章为" + id);
        return backCourseService.aSelectContent(id);
    }

    //新增文章
    @PostMapping(value = "/content")
    public ResultBean aInsertContent(Course course) {
        log.info("新增加文章对象为" + course);
        return backCourseService.aInsertContent(course);
    }

    //更新文章
    @PutMapping(value = "/content")
    public ResultBean aUpdateContent(Course course) {
        log.info("修改文章为" + course);
        return backCourseService.aUpdateContent(course);
    }


}
